package cocurrency.countdownlatch;

import java.util.concurrent.CountDownLatch;

/**
 * Created by luzl on 4/6/2017.
 */
public class CountDownLatchThread extends Thread{
    private CountDownLatch prepareLatch;
    private CountDownLatch startLatch;
    private CountDownLatch completeLatch;
    private String name;

    public  CountDownLatchThread(CountDownLatch prepareLatch, CountDownLatch startLatch, CountDownLatch completeLatch, String name){
        this.prepareLatch=prepareLatch;
        this.startLatch=startLatch;
        this.completeLatch=completeLatch;
        this.name=name;
    }

    public void run(){
        System.out.println(this.name+" waiting command to start");
        prepareLatch.countDown();

        try {
            startLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(this.name+" executing Task! ");
        this.completeLatch.countDown();
    }
}
